<template>
	<view style="padding-bottom: 130rpx;">
		<view class="formContainer">
			<uni-forms ref="form">
				<uni-forms-item label="同行名称" required>
					<view>
						<u--input v-model="formData.name" placeholder="请输入同行名称"></u--input>
					</view>
				</uni-forms-item>

				<uni-forms-item label="联系人">
					<view>
						<u--input v-model="formData.contact" placeholder="请输入联系人"></u--input>
					</view>
				</uni-forms-item>

				<uni-forms-item label="联系电话">
					<view>
						<u--input v-model="formData.phone" placeholder="请输入联系电话" type="number" maxlength="11">
						</u--input>
					</view>
				</uni-forms-item>
                <uni-forms-item label="公司电话">
                	<view>
                		<u--input v-model="formData.companyPhone" placeholder="请输入公司电话" type="number"></u--input>
                	</view>
                </uni-forms-item>

				<uni-forms-item label="公司地址">
					<view>
						<u--input v-model="formData.companyAddress" placeholder="请输入公司地址"></u--input>
					</view>
				</uni-forms-item>

				

				<uni-forms-item label="备注" labelPosition="top">
					<view>
						<u--textarea v-model="formData.remark" placeholder="请输入200字以内的内容" count maxlength="200">
						</u--textarea>
					</view>
				</uni-forms-item>
			</uni-forms>
		</view>

		<button type="info" class="sub-btn" @click="confimCar">确认</button>

	</view>
</template>

<script>
	import * as secondedApi from '@/api/seconded-api.js';
	export default {

		data() {
			return {
				type: 0,
				showCarKeyboard: false,
				formData: {
					id: '',
					name: '',
					remark: '',
					contact: '',
					phone: '',
					companyAddress: '',
					companyPhone: '',
					remark: ''
				}

			};
		},

		onLoad(op) {
			if (op) {
				this.type = op.type;
				this.formData.id = op.id;
				uni.setNavigationBarTitle({
					title: this.type == 1 ? '编辑同行' : '新增同行'
				})
			}
			
			if(this.type == 1) {
				this.getPeerDetail();
			}
			
		},
		methods: {
			getPeerDetail() {
			  secondedApi.peerDetail(this.formData.id).then(res=>{
				  this.formData = res.data;
			  })	
			},
			
			
			// 确认
			confimCar() {
				if (uni.$u.test.isEmpty(this.formData.name)) {
					uni.$u.toast('请选择借调同行');
					return
				} else {
					
					
					
					uni.showModal({
						title: '提示',
						content: this.type == 1 ? '确认编辑该同行吗?' : '确认添加该同行吗?', 
						cancelText: '取消',
						confirmText: '确认',
						success: (res) => {
							if (res.confirm) {
								if(this.type == 1) {
									secondedApi.editPeer(this.formData).then(res1 => {
										if (res1.code == 200) {
											uni.$emit('refreshSecondedList');
											uni.navigateBack();
										}
									})
								}else {
									secondedApi.addPeer(this.formData).then(res1 => {
										if (res1.code == 200) {
											uni.$emit('refreshSecondedList');
											uni.navigateBack();
										}
									})
								}
								
							}
						}
					})
				}


			}
		}
	};
</script>

<style lang="scss" scoped>
	.formContainer {
		margin: 40rpx 20rpx;
		padding: 24rpx;
		background-color: #fff;
		box-shadow: 0px 4rpx 16rpx 0px rgba(1, 10, 18, 0.1);
		border-radius: 16rpx;
	}
</style>
